package com.commont;

import com.Util.Config;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by acans on 16/6/17.
 */
@Slf4j
public class DatabasePool {
    private HikariDataSource database;
    private HikariConfig databaseConfiguration;

    public boolean getStoragePooling() {
        try {
            this.databaseConfiguration = new HikariConfig ();
            this.databaseConfiguration.setMaximumPoolSize(20);
            this.databaseConfiguration.setDriverClassName("com.mysql.jdbc.Driver");
            this.databaseConfiguration.setJdbcUrl( Config.mysql_jdbcurl);
            log.info ( "信息1={}",Config.mysql_jdbcurl );
            //this.databaseConfiguration.setJdbcUrl("");
            this.databaseConfiguration.setUsername(Config.mysql_user);
            this.databaseConfiguration.setPassword(Config.mysql_password);
            this.databaseConfiguration.setAutoCommit(true);
            this.databaseConfiguration.setMaxLifetime(120000000L);
            this.databaseConfiguration.setConnectionTestQuery("SELECT 1");
            this.databaseConfiguration.setPoolName("jerseyTest");
            this.database = new HikariDataSource (this.databaseConfiguration);

        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public HikariDataSource getDatabase() {
        return this.database;
    }
}
